package com.zhfi.dataapply.service.common.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.zhfi.dataapply.entity.job.JobRangeDateObj;
import com.zhfi.dataapply.mapper.common.JobRangeDateMapper;
import com.zhfi.dataapply.service.common.JobRangeDateService;
import com.zhfi.dataapply.util.DateTimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class JobRangeDateServiceImpl implements JobRangeDateService {

    @Autowired
    private JobRangeDateMapper jobRangeDateMapper;


    @Override
    public JobRangeDateObj getRangeDateParam(String jobId) {
        return jobRangeDateMapper.selectById(jobId);
    }

    @Override
    public int updateRangeDate(String jobName, Date startDate, Date endDate) {
        UpdateWrapper<JobRangeDateObj> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("job_name", jobName);
        JobRangeDateObj jobRangeDateObj = new JobRangeDateObj();
        jobRangeDateObj.setStartDate(DateTimeUtil.transToDateString(startDate));
        jobRangeDateObj.setEndDate(DateTimeUtil.transToDateString(endDate));
        return jobRangeDateMapper.update(jobRangeDateObj, updateWrapper);
    }

    @Override
    public int updateEndDate(String jobName, Date endDate) {
        UpdateWrapper<JobRangeDateObj> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("job_name", jobName);
        JobRangeDateObj jobRangeDateObj = new JobRangeDateObj();
        jobRangeDateObj.setEndDate(DateTimeUtil.transToDateString(endDate));
        return jobRangeDateMapper.update(jobRangeDateObj, updateWrapper);
    }
}
